package gomoku_env

type GameState interface {
	GetLegalActions() []Action
	GetState() State
	Move(action Action) (State, error)
	IsTerminal() bool
	GetResult() float64
}

func (env *GomokuEnv) GetLegalActions() []*Action {
	var actions []*Action
	for i := 0; i < BoardSize; i++ {
		for j := 0; j < BoardSize; j++ {
			if env.board[i][j] == Empty {
				actions = append(actions, &Action{X: i, Y: j})
			}
		}
	}
	return actions
}

func (env *GomokuEnv) Move(a *Action) (State, error) {
	s, _, _, err := env.Step(a.X, a.Y)
	return s, err
}

func (env *GomokuEnv) IsTerminal() bool {
	return env.done
}

func (env *GomokuEnv) GetResult() float64 {
	if env.done {
		return 1.0 * float64(env.winner)
	}
	return 0
}

func (env *GomokuEnv) GetState() State {
	return env.board
}
